package Solutions;

public class Solustion16 {
    public static void main(String[] args) {
       Solution016 solution016 = new Solution016();
       solution016.masterMind("RGRB","BBBY");
    }
}
class Solution016 {
    public int[] masterMind(String solution, String guess) {
   char[] sol = solution.toCharArray();
        char[] gue = guess.toCharArray();
        int[] res = new int[2];
        //先把猜对的挑出来
        // 把相同的当成一次猜中，并把这两个字符抵消
        for(int i = 0; i < sol.length; i++){
            if(sol[i] == gue[i]){
                sol[i] = ' ';//把两个字符都变成空
                gue[i] = ' ';
                res[0]++;
            }
        }
        //再把伪猜对的挑出来
        //再次遍历guess中的每一位，在solution中搜索是否有这个字符，如果有则抵消solution和guess中的字符
        for(int i = 0; i < gue.length; i++){
            if(gue[i] != ' '){
                for(int j = 0; j < sol.length; j++){
                    if(sol[j] == gue[i]){
                        sol[j] = ' ';
                        gue[i] = ' ';
                        res[1]++;
                        break;
                    }
                }
            }
        }
        return res;
    }
}